﻿using ReactiveUI;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Windows;

namespace ScienceAIApp.Views.AlertView
{
    /// <summary>
    /// Interaction logic for SeriesChooseView.xaml
    /// </summary>
    public partial class SeriesChooseView
    {
        public SeriesChooseView()
        {
            InitializeComponent();
            this.WhenActivated(_activated);
        }

        private void _activated(CompositeDisposable disposable)
        {

            this.OneWayBind(
                    ViewModel,
                    vm => vm.PageCount,
                    v => v.PageCount.Text)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.PageNum,
                    v => v.PageNum.Text)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.IsCanPre,
                    v => v.PreBtn.IsEnabled)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.IsCanNext,
                    v => v.NextBtn.IsEnabled)
                .DisposeWith(disposable);

            this.BindCommand(
                ViewModel,
                vm => vm.TurnPageCommand,
                v => v.PreBtn,
                Observable.Return(Convert.ToInt32(this.PageNum.Text) - 1)
            ).DisposeWith(disposable);

            this.BindCommand(
                ViewModel,
                vm => vm.TurnPageCommand,
                v => v.NextBtn,
                Observable.Return(Convert.ToInt32(this.PageNum.Text) + 1)
            ).DisposeWith(disposable);

            this.BindCommand(
                ViewModel,
                vm => vm.ConfirmCommand,
                v => v.OkBtn
            ).DisposeWith(disposable);

            this.BindCommand(
                ViewModel,
                vm => vm.CancelCommand,
                v => v.CancelBtn
            ).DisposeWith(disposable);

            this.OneWayBind(
                ViewModel,
                vm => vm.AlertMsg,
                v=>v.AlertMsg.Text
                ).DisposeWith(disposable);

            // 列表绑定
            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm1,
                    v => v.Series1Host.ViewModel)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm2,
                    v => v.Series2Host.ViewModel)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm3,
                    v => v.Series3Host.ViewModel)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm4,
                    v => v.Series4Host.ViewModel)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm5,
                    v => v.Series5Host.ViewModel)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm6,
                    v => v.Series6Host.ViewModel)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm7,
                    v => v.Series7Host.ViewModel)
                .DisposeWith(disposable);

            // 列表 border 展示
            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm1.CurrentSeries,
                    v => v.Series1Border.Visibility,
                    si => si == null ? Visibility.Collapsed : Visibility.Visible)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm2.CurrentSeries,
                    v => v.Series2Border.Visibility,
                    si => si == null ? Visibility.Collapsed : Visibility.Visible)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm3.CurrentSeries,
                    v => v.Series3Border.Visibility,
                    si => si == null ? Visibility.Collapsed : Visibility.Visible)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm4.CurrentSeries,
                    v => v.Series4Border.Visibility,
                    si => si == null ? Visibility.Collapsed : Visibility.Visible)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm5.CurrentSeries,
                    v => v.Series5Border.Visibility,
                    si => si == null ? Visibility.Collapsed : Visibility.Visible)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm6.CurrentSeries,
                    v => v.Series6Border.Visibility,
                    si => si == null ? Visibility.Collapsed : Visibility.Visible)
                .DisposeWith(disposable);

            this.OneWayBind(
                    ViewModel,
                    vm => vm.SeriesVm7.CurrentSeries,
                    v => v.Series7Border.Visibility,
                    si => si == null ? Visibility.Collapsed : Visibility.Visible)
                .DisposeWith(disposable);

        }
    }
}
